from api.common.excel_util import Excel
from api.config.config import Config
import json
class PetData:

    @staticmethod
    def petTestCase(torow = None):
        # excel = Excel('D:/workspace/2021/webflash20/venv/api/data/testcases.xlsx')
        excel = Excel(Config().testCaseFile)
        excel.open()
        if torow:
            lastrow = torow
        else:
            lastrow = excel.get_rows_count()

        data = excel.get_range_value('A2',f'M{lastrow}')
        excel.close()
        return data

    @staticmethod
    def petTestCaseJson():
        # json<-->dict
        # json.dump/json.dumps，json.load/json.loads
        # json.dumps  json.loads  --内存中对象转换
        # json.dump   json.load   --内存到文件之间的转换
        with open(Config().testCaseJsonFile, 'r', encoding='UTF-8') as f:
            data = json.load(f)
            return data.get('data')

class CaseTitle:
    module = 0
    id = 1
    casename = 2
    url = 3
    method = 4
    params = 5
    headers = 6
    body = 7
    bodtype = 8
    status_code = 9
    message = 10
    result = 11
    tester = 12

class CaseTitleText:
    module = 'module'
    id = 'id'
    casename = 'casename'
    url = 'url'
    method = 'method'
    params = 'params'
    headers = 'headers'
    body = 'body'
    bodtype = 'bodytype'
    status_code = 'status_code'
    message = 'message'
    result = 'result'
    tester = 'tester'

# class LoginData:
#     @staticmethod
#     def loginTestCase():
#         # 数据存储格式：
#         # 1、excel；2、json；3、yaml；4、xml
#         data = [{'username': 'developer', 'password': 'developer', 'checkpoint': [{'code': 20000}, {'msg': '成功'}]},
#                 {'username': '', 'password': '', 'checkpoint': [{'code': 9999}, {'msg': '登录时失败'}]},
#                 {'username': 'huice', 'password': '', 'checkpoint': [{'code': 9999}]},
#                 {'username': '', 'password': '123', 'checkpoint': [{'code': 9999}, {'msg': '登录时失败'}]},
#                 {'username': 'huice', 'password': '123', 'checkpoint': [{'code': 9999}, {'msg': '登录时失败'}]}
#                 ]
#         return data
#
#
# class DeptData:
#
#     @staticmethod
#     def simplename():
#         """
#         部门名称
#         :return:
#         """
#         from mimesis import Business
#         p = Business('zh')
#         return p.company()
#
#     @staticmethod
#     def seqnum():
#         from mimesis import Numbers
#         n = Numbers()
#         return n.integer_number(1,10)